﻿using System;
using Android.Content;
using Android.OS;
using Android.Views;
using Xamarin.ActionbarSherlockBinding.App;
using Xamarin.ActionbarSherlockBinding.Widget;
using Cinemacenter.Shared;

namespace Cinemacenter.Droid
{
	public class UpcomingDetailsFragment : SherlockFragment
	{
		UpcomingMovie movie;
		ShareActionProvider mShareActionProvider;

		public override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
			HasOptionsMenu = true;
			RetainInstance = true;
			var movieId = Arguments.GetInt ("movieId");
			movie = DBHelper.GetUpcoming (movieId);
			Activity.ActionBar.Title = movie.Name;
		}

		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			View detailsView;
			return null;
		}

		public override void OnViewCreated (View view, Bundle savedInstanceState)
		{
			base.OnViewCreated (view, savedInstanceState);
		}

		Intent getDefaultShareIntent ()
		{
			var intent = new Intent (Intent.ActionSend);
			intent.SetType ("text/plain");
			intent.PutExtra (Intent.ExtraSubject, Resource.String.app_name);
			intent.PutExtra (Intent.ExtraText, movie.Name + " próximamente en Cinemacenter. Más info => " + movie.Link);
			return intent;
		}

		public override void OnCreateOptionsMenu (Xamarin.ActionbarSherlockBinding.Views.IMenu menu, Xamarin.ActionbarSherlockBinding.Views.MenuInflater inflater)
		{
			inflater.Inflate (Resource.Menu.activity_details, menu);
			mShareActionProvider = (ShareActionProvider)menu.FindItem (Resource.Id.menu_share_app).ActionProvider;
			Intent intent = getDefaultShareIntent ();
			if (intent != null)
				mShareActionProvider.SetShareIntent (intent);
			base.OnCreateOptionsMenu (menu, inflater);
		}
	}
}